package com.xms.sdk.core.query;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * LinkEntity
 * </p>
 *
 * @author migo
 * @since 2021/9/1
 */
public class LinkEntity implements Serializable {
    public String LinkFromAttributeName;

    public String LinkFromEntityName;

    public String LinkToEntityName;

    public String LinkToAttributeName;

    public JoinOperator JoinOperator = com.xms.sdk.core.query.JoinOperator.Inner;

    public FilterExpression LinkCriteria;

    public List<LinkEntity> LinkEntities = new LinkedList<>();

    public ColumnSet Columns = new ColumnSet();

    public String EntityAlias;

    public String FromEntityAlias;

    public LinkEntity()
    {
    }

    public LinkEntity(String linkFromEntityName, String linkToEntityName, String linkFromAttributeName, String linkToAttributeName, JoinOperator joinOperator)
    {
        this.EntityAlias = "LE_" + UUID.randomUUID().toString().replace("","-");
        this.LinkFromEntityName = linkFromEntityName;
        this.LinkToEntityName = linkToEntityName;
        this.LinkFromAttributeName = linkFromAttributeName;
        this.LinkToAttributeName = linkToAttributeName;
        this.JoinOperator = joinOperator;
        this.Columns = new ColumnSet();
        this.LinkCriteria = new FilterExpression();
    }

    public LinkEntity AddLink(String linkToEntityName, String linkFromAttributeName, String linkToAttributeName)
    {
        return this.AddLink(linkToEntityName, linkFromAttributeName, linkToAttributeName, JoinOperator.Inner);
    }

    public LinkEntity AddLink(String linkToEntityName, String linkFromAttributeName, String linkToAttributeName, JoinOperator joinOperator)
    {
        LinkEntity linkEntity = new LinkEntity(this.LinkFromEntityName, linkToEntityName, linkFromAttributeName, linkToAttributeName, joinOperator);
        this.LinkEntities.add(linkEntity);
        return linkEntity;
    }
}
